﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _线程
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            Thread td = new Thread(Clicks);
            td.Start();


        }

        public bool State = false;

        public void Clicks()
        {
            State = true;
            string Conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ToString();

            //while (State)
            //{
                //Thread.Sleep(1000);
                using (SqlConnection conn = new SqlConnection(Conn))
                {
                    using (SqlCommand cmd = new SqlCommand("Select RoleName,* from BaseRole", conn))
                    {
                        conn.Open();
                        //cmd.Parameters.AddRange();
                        DataSet ds = new DataSet();
                        SqlDataAdapter sda = new SqlDataAdapter(cmd);
                        sda.Fill(ds);
                        DgvUsersState.DataSource = ds.Tables[0];
                    }
                //}
            }

        }

        private void btnEnd_Click(object sender, EventArgs e)
        {
            State = false;
        }
    }
}
